// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-7-12 11:54:29
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   t_user_Manager.java

package com.creawor.hz_market.t_user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.hibernate.HibernateException;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.creawor.hz_market.t_role.t_role_QueryMap;
import com.creawor.hz_market.util.LoginUtils;
import com.creawor.imei.base.BaseAction;
import com.creawor.km.util.CatcheUtil;

// Referenced classes of package com.creawor.hz_market.t_user:
//            t_user_QueryMap, t_user_Form, t_user_EditMap, t_user

public class t_user_Manager extends BaseAction
{

    public t_user_Manager()
    {
    }

    public String doList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        String pagenos = request.getParameter("pageno");
        String pagesizes = request.getParameter("pagesize");
        try
        {
            pageno = Integer.valueOf(pagenos);
        }
        catch(NumberFormatException e)
        {
            pageno = new Integer(1);
        }
        if(pagesizes != null)
            pagesize = Integer.valueOf(pagesizes.trim());
        t_user_QueryMap query_map = new t_user_QueryMap();
        query_map.pageno = pageno;
        query_map.pagesize = pagesize;
        java.util.Iterator sl = null;
        if(sql_string == null || sql_string.equals("") || sql_string.equalsIgnoreCase("null"))
        {
        	List list=null;
        	list=(List)CatcheUtil.getInstance().getSYSObject("t_userList_1");
        	if(null==list){
        		list=query_map.findAll();
        		CatcheUtil.getInstance().cacheSYSObj("t_userList_1", list);
        	}
           sl = list.iterator();
           
           // sl = query_map.findAll().iterator();
        } else
        {
        	List list=null;
        	list=(List)CatcheUtil.getInstance().getSYSObject("t_userList_2");
        	if(null==list){
        		list= query_map.findAllList(sql_string, sql_param);
        		CatcheUtil.getInstance().cacheSYSObj("t_userList_2", list);
        	}
           // sl = query_map.findAll(sql_string, sql_param);
            sl=list.listIterator();
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
        }
        request.setAttribute("sl", sl);
        retriveDeptCodeList(request);
        request.setAttribute("curpageno", pageno);
        if(pageno.intValue() > 1)
            request.setAttribute("prepage", new Integer(pageno.intValue() - 1));
        else
            request.setAttribute("prepage", new Integer(1));
        int totalpage = 0;
        if(query_map.totalrow % pagesize.intValue() == 0)
            totalpage = query_map.totalrow / pagesize.intValue();
        else
            totalpage = query_map.totalrow / pagesize.intValue() + 1;
        request.setAttribute("totalpage", new Integer(totalpage));
        if(pageno.intValue() < totalpage)
            request.setAttribute("nextpage", new Integer(pageno.intValue() + 1));
        else
            request.setAttribute("nextpage", new Integer(totalpage));
        String act=request.getParameter("act");
        if(null!=act && "list1".equalsIgnoreCase(act))
        {
        	return "list1";
        }else{
        	
        	return "list";
        }
    }
    
    //count

    public String doCount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        String pagenos = request.getParameter("pageno");
        String pagesizes = request.getParameter("pagesize");
        try
        {
            pageno = Integer.valueOf(pagenos);
        }
        catch(NumberFormatException e)
        {
            pageno = new Integer(1);
        }
        if(pagesizes != null)
            pagesize = Integer.valueOf(pagesizes.trim());
        t_user_QueryMap query_map = new t_user_QueryMap();
        query_map.pageno = pageno;
        query_map.pagesize = pagesize;
        java.util.Iterator sl = null;
        if(sql_string == null || sql_string.equals("") || sql_string.equalsIgnoreCase("null"))
        {
        	List list=null;
        	list=(List)CatcheUtil.getInstance().getSYSObject("t_userList_1");
        	if(null==list){
        		list=query_map.findAll();
        		CatcheUtil.getInstance().cacheSYSObj("t_userList_1", list);
        	}
           sl = list.iterator();
           
           // sl = query_map.findAll().iterator();
        } else
        {
        	List list=null;
        	list=(List)CatcheUtil.getInstance().getSYSObject("t_userList_2");
        	if(null==list){
        		list= query_map.findAllList(sql_string, sql_param);
        		CatcheUtil.getInstance().cacheSYSObj("t_userList_2", list);
        	}
           // sl = query_map.findAll(sql_string, sql_param);
            sl=list.listIterator();
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
        }
        request.setAttribute("sl", sl);
        retriveDeptCodeList(request);
        request.setAttribute("curpageno", pageno);
        if(pageno.intValue() > 1)
            request.setAttribute("prepage", new Integer(pageno.intValue() - 1));
        else
            request.setAttribute("prepage", new Integer(1));
        int totalpage = 0;
        if(query_map.totalrow % pagesize.intValue() == 0)
            totalpage = query_map.totalrow / pagesize.intValue();
        else
            totalpage = query_map.totalrow / pagesize.intValue() + 1;
        request.setAttribute("totalpage", new Integer(totalpage));
        if(pageno.intValue() < totalpage)
            request.setAttribute("nextpage", new Integer(pageno.intValue() + 1));
        else
            request.setAttribute("nextpage", new Integer(totalpage));
        return "count";
    }


    private void retriveDeptCodeList(HttpServletRequest request)
        throws RuntimeException
    {
        try
        {
//            v_service_hall_QueryMap deptCodeQueryMap = new v_service_hall_QueryMap();
//            deptCodeQueryMap.setPagesize(10000);
//            List it_v_service_hall = deptCodeQueryMap.findAll();
//            v_area_QueryMap v_area_queryMap = new v_area_QueryMap();
//            v_area_queryMap.setPagesize(10000);
//            List it_v_area = v_area_queryMap.findAll();
//            request.setAttribute("v_service_hall_list", it_v_service_hall);
//            request.setAttribute("v_area_list", it_v_area);
        }
        catch(Exception e)
        {
            throw new IllegalStateException(e.toString());
        }
    }

    public String doDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        try
        {
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        t_user_QueryMap sqm = new t_user_QueryMap();
        String uid = request.getParameter("id");
        t_user_Form sf = null;
        sf = sqm.getByID(uid);
        request.setAttribute("t_user_Form", sf);
        retriveRoles(request);
        retriveDeptCodeList(request);
        return "detail";
    }
    
    

    public String doCreate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        request.setAttribute("t_user_Form", new t_user_Form());
        retriveRoles(request);
        retriveDeptCodeList(request);
        return "addpage";
    }

    private void retriveRoles(HttpServletRequest request)
    {
        try
        {
            request.setAttribute("roles", (new t_role_QueryMap()).findAll());
        }
        catch(HibernateException e)
        {
            e.printStackTrace();
        }
    }

    public String doAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        t_user_EditMap editMap = new t_user_EditMap();
        try
        {
            t_user_Form vo = null;
            vo = (t_user_Form)form;
            editMap.add(vo);
        }
        catch(HibernateException e)
        {
            ActionErrors errors = new ActionErrors();
            errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.database.save", e.toString()));
            saveErrors(request, errors);
            e.printStackTrace();
            request.setAttribute("t_user_Form", form);
            return "addpage";
        }
        return "aftersave";
    }

    public String doQuery(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        return "searchpage";
    }
    
    public String doQuery1(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        return "searchpage1";
    }

    public String doEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        try
        {
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        retriveRoles(request);
        t_user_QueryMap query_map = new t_user_QueryMap();
        String uid = request.getParameter("id");
        t_user_Form vo = null;
        query_map.session.flush();
        vo = query_map.getByID(uid);
        request.setAttribute("t_user_Form", vo);
        retriveDeptCodeList(request);
        return "editpage";
    }

    public String doUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        try
        {
            t_user_EditMap edit_map = new t_user_EditMap();
            t_user_Form vo = null;
            vo = (t_user_Form)form;
            edit_map.update(vo);
        }
        catch(HibernateException e)
        {
            ActionErrors errors = new ActionErrors();
            errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.database.save", e.toString()));
            saveErrors(request, errors);
            e.printStackTrace();
            request.setAttribute("t_user_Form", form);
            return "editpage";
        }
        return "aftersave";
    }

    public String doDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        t_user_EditMap edit_map = new t_user_EditMap();
        String uid = request.getParameter("id");
        try
        {
            edit_map.delete(uid);
        }
        catch(HibernateException e)
        {
            ActionErrors errors = new ActionErrors();
            errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.database.save", e.toString()));
            saveErrors(request, errors);
            e.printStackTrace();
            return "list";
        }
        return "aftersave";
    }

    public String doOther(ActionMapping mapping, ActionForm form, String action, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        if("changePassword".equals(action))
            return doChangePassword(mapping, form, request, response);
        else
            return doList(mapping, form, request, response);
    }

    private String doChangePassword(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws HibernateException
    {
        t_user_QueryMap queryMap = new t_user_QueryMap();
        t_user user = (t_user)queryMap.get(t_user.class, new Integer(LoginUtils.getLoginUser(request).getUserId()));
        if(!user.getPassword().equals(request.getParameter("oldPassword")))
        {
            addDirectError(request, "\u65E7\u5BC6\u7801\u9519\u8BEF");
            return "changePasswordInput";
        } else
        {
            addDirectMessage(request, "\u4FEE\u6539\u5BC6\u7801\u6210\u529F");
            user.setPassword(request.getParameter("password"));
            queryMap.save(user);
            return "afterChangePassword";
        }
    }

    public void addDirectMessage(HttpServletRequest request, String message)
    {
        ActionMessages messages = new ActionMessages();
        messages.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage("message", message));
        saveMessages(request, messages);
    }

    public void addDirectError(HttpServletRequest request, String errorMsg)
    {
        ActionErrors errors = new ActionErrors();
        errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("message", errorMsg));
        saveErrors(request, errors);
    }

    static Class class$0;
}